/*
 * PayFailedListItem.java
 * business
 *
 * Created by ChenTao on 2017/2/28.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.data.bean.Order;
import com.yidiandao.business.data.response.QueryOrderResultResponse;
import com.yidiandao.business.ui.orderabout.orderdetail.OrderDetailActivity;
import com.yidiandao.business.ui.url.UrlActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.PayFailedHolder;

/**
 * 购买/支付失败-ListItem
 *
 * <p>Created by ChenTao(chentao7v@gmail.com) on 2017/2/21 16:19
 */
public class PayFailedListItem
        extends DisplayListItem<PayFailedHolder, QueryOrderResultResponse.Data> {

    public PayFailedListItem(QueryOrderResultResponse.Data s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, PayFailedHolder holder) {
        holder.refreshUI(data);

        // 重新支付
        holder.tvPayAgain.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        UrlActivity.actionStartForOnlinePay(
                                (Activity) context, data.getUrl(), data.getOrderPayId(), false);
                    }
                });

        // 查看订单
        holder.tvShowOrder.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        OrderDetailActivity.actionStart((Activity) context, getFirstOrderId(data));
                    }
                });
    }

    private String getFirstOrderId(QueryOrderResultResponse.Data data) {
        Order firstOrder = data.getOrderList().get(0);
        return firstOrder.getOrderId();
    }

    @Override
    public String getDisplayItemTag() {
        return PayFailedListItem.class.getSimpleName();
    }

    @Override
    public Class<PayFailedHolder> getViewHolderClazz() {
        return PayFailedHolder.class;
    }
}
